package com.ww.springboot.boot.javabase.proxy.demo3;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * 描述：
 *
 * @author wanwei
 * @since 2021-11-01 09:38
 */
public class MyInvocation implements InvocationHandler {

    private People people;

    public MyInvocation(People people) {
        this.people = people;
    }

    public static Object wrap(People target) {
        return Proxy.newProxyInstance(target.getClass().getClassLoader(),
                target.getClass().getInterfaces(), new MyInvocation(target));
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("----------入代理--------");
        System.out.println(proxy.getClass().getName());
        System.out.println(method.getName());
        System.out.println(args);
        Object object = method.invoke(people, args);
        System.out.println("----------出代理--------");
        return object;
    }
}
